package com.lagou.dao.impl;

import com.lagou.dao.IUserDao;
import com.lagou.io.Resources;
import com.lagou.pojo.User;
import com.lagou.sql.SqlSessionFactory;
import com.lagou.sql.SqlSessionFactoryBuilder;
import com.lagou.sql.session.SqlSession;

import java.io.InputStream;
import java.util.List;

/**
 * @author Kirito
 * @description:
 * @date 2020/03/26
 */
public class UserDaoImpl implements IUserDao {
    @Override
    public User findUserByCondition(User user) throws Exception {
        InputStream resources = Resources.getResourcesAsStream("sqlMapConfig.xml");
        SqlSessionFactory sqlSessionFactory = SqlSessionFactoryBuilder.build(resources);
        SqlSession sqlSession = sqlSessionFactory.openSqlSession();
        return sqlSession.selectOne("User.selectOne", user);
    }

    @Override
    public List<User> findAll() throws Exception {
        InputStream resources = Resources.getResourcesAsStream("sqlMapConfig.xml");
        SqlSessionFactory sqlSessionFactory = SqlSessionFactoryBuilder.build(resources);
        SqlSession sqlSession = sqlSessionFactory.openSqlSession();
        return sqlSession.selectList("User.selectList", null);
    }
}
